package io.renren.modules.question.controller;

import io.renren.common.utils.IdDto;
import io.renren.common.utils.PageInput;
import io.renren.common.utils.PageUtils;
import io.renren.modules.question.dto.input.QuestionInput;
import io.renren.modules.question.dto.input.UpdateQuestionInput;
import io.renren.modules.question.dto.output.QuestionOutput;
import io.renren.modules.question.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author liangbaigao
 * @Date 2022/10/6 16:43
 */
@Api(tags = "添加问卷模块")
@RestController
@RequestMapping("/question")
public class QuestionController {

    @Resource
    private QuestionService questionService;

    /**
     * 新增问卷
     * @param questionInput 问卷信息
     */
    @ApiOperation("新增问卷")
    @PostMapping("/addQuestion")
    public void addQuestion(@Valid @RequestBody QuestionInput questionInput){
        questionService.addQuestion(questionInput);
    }

    /**
     * 更改问卷信息
     */
    @PostMapping("/updateQuestion")
    @ApiOperation("更改问卷信息")
    public void updateQuestion(@Valid @RequestBody UpdateQuestionInput input){
        questionService.updateQuestion(input);
    }

    /**
     * 删除问卷
     */
    @PostMapping("/deleteQuestion")
    @ApiOperation("删除问卷")
    public void deleteQuestion(@RequestBody @Valid IdDto id){
        questionService.deleteQuestion(id);
    }

    /**
     * 发布问卷
     */
    @PostMapping("/publishQuestion")
    @ApiOperation("发布问卷")
    public void publishQuestion(@RequestBody @Valid IdDto id){
        questionService.publishQuestion(id);
    }

    /**
     * 查看问卷分页
     */
    @ApiOperation("查看问卷分页")
    @PostMapping("/showQuestion")
    public PageUtils showQuestion(@RequestBody @Valid PageInput pageInput){
        return questionService.showQuestion(pageInput);
    }

    /**
     * 问卷详情
     */
    @ApiOperation("问卷详情")
    @PostMapping("/questionDetail")
    public QuestionOutput questionDetail(@Valid @RequestBody IdDto id){
        return questionService.questionDetail(id);
    }
}
